<?php

//get all customer	
function getAllCustomer(){
	$qr ="SELECT * FROM customer";
	return mysql_query($qr);
}

//add customer	
function addCustomer($customerName,$birthday,$email,$phone,$addressID,$registerYear,$registerMonth){
	$qr ="INSERT INTO customer(CustomerName,Birthday,Email,Phone,AddressID,RegisterYear,RegisterMonth) VALUES('$customerName','$birthday','$email','$phone','$addressID','$registerYear','$registerMonth')";
	mysql_query($qr);
}

//get customer by id	
function getCustomerByID($customerID){
	$qr ="SELECT * FROM customer WHERE CustomerID = $customerID;";
	return mysql_query($qr);
}

//edit customer	
function editCustomer($customerName,$birthday,$email,$phone,$registerYear,$registerMonth,$customerID){
	$qr ="UPDATE customer 
	SET CustomerName = '$customerName',
	Birthday = '$birthday',
	Email = '$email',
	Phone = '$phone',
	RegisterYear = '$registerYear', 
	RegisterMonth = '$registerMonth'  
	WHERE CustomerID = $customerID; ";
	mysql_query($qr);
}

//edit customer	amount total and customer type, just more "," after '$customerTypeID', it not work
function editCustomerAmountTotalAndCustomerType($customerAmountTotal,$customerTypeID,$customerID){
	$qr ="UPDATE customer 
	SET CustomerAmountTotal = '$customerAmountTotal',
	CustomerTypeID = '$customerTypeID'
	WHERE CustomerID = $customerID; ";
	mysql_query($qr);
}

//delete customer	
function deleteCustomer($customerID){
	$qr ="DELETE FROM customer WHERE CustomerID = $customerID";
	mysql_query($qr);
}

//get total number of customer
function getTotalNumberOfCustomer(){
	$listcustomer = getAllCustomer();
	if($listcustomer == NULL) return 0;
	return mysql_num_rows($listcustomer);
}

//get total number of customer in specific type
function getTotalNumberOfCustomerInSpecificType($type){
	$qr ="SELECT * FROM customer WHERE CustomerTypeID = $type;";
	$listCustomerInType = mysql_query($qr);
	if($listCustomerInType == NULL) return 0;
	return mysql_num_rows($listCustomerInType);
}

//get number customer register by month in year
function getNumberCustomerRegisterByMonthInYear($year, $month){
	$qr ="SELECT * FROM customer WHERE RegisterYear = $year AND RegisterMonth = $month;";
	$listCustomerRegisterByMonthInYear = mysql_query($qr);
	if($listCustomerRegisterByMonthInYear == NULL) return 0;
	return mysql_num_rows($listCustomerRegisterByMonthInYear);
}


?>